import xlsxwriter

# 新建文件
workbook = xlsxwriter.Workbook('expenses.xlsx')
# 新建sheet,并指定sheet名称
worksheet = workbook.add_worksheet('employee')
# 将要写入的数据，二维元祖
expenses = (['Rent', 1000], ['Gas', 100], ['Food', 300], ['Gym', 50])
# 按标号写入是从0开始的，按绝对位置'A1'写入是从1开始
row = 0
col = 0

# 遍历数据并逐行将其写入
for item, cost in expenses:
    worksheet.write(row, col, item)
    worksheet.write(row, col + 1, cost)
    row += 1
# 写入公式
worksheet.write(row, 0, 'Total:')
worksheet.write(row, 1, '=SUM(B1:B4)')  # 求和公式

workbook.close()
